package com.wjx.reservation_service.dao;

import com.wjx.reservation_service.model.Rating;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RatingDao {
    //根据服务id查询评价
    @Select("select * from rating where service_id = #{serviceId} order by id desc")
    public List<Rating> queryRatingByServiceId(int serviceId);
    //根据id更新评分、反馈、最后更新时间
    @Update("update rating set score = #{score},feedback = #{feedback},last_updated_time = #{lastUpdatedTime} where id = #{id}")
    public int updateScoreById(int id,int score,String feedback,String lastUpdatedTime);
    //根据id删除评价
    @Delete("delete from rating where id = #{id}")
    public int deleteRatingById(int id);
    //根据id查询评价
    @Select("select * from rating where id = #{id}")
    public Rating queryRatingById(int id);
    //根据预约id查询评价
    @Select("select * from rating where appointment_id = #{appointmentId}")
    public Rating queryRatingByAppointmentId(int appointmentId);
    //添加评价
    @Insert("insert into rating (service_id,appointment_id,user_id,score,feedback,created_time,last_updated_time)" +
            "values (#{serviceId},#{appointmentId},#{userId},#{score},#{feedback},#{createdTime},#{lastUpdatedTime})")
    public int addRating(Rating rating);
    //根据服务id删除评价
    @Delete("delete from rating where service_id = #{serviceId}")
    public int deleteRatingByServiceId(int serviceId);
    //根据用户id删除评价
    @Delete("delete from rating where user_id = #{userId}")
    public int deleteRatingByUserId(int userId);
    //根据预约id删除评价
    @Delete("delete from rating where appointment_id = #{appointmentId}")
    public int deleteRatingByAppointmentId(int appointmentId);
    //查询所有评价
    @Select("select * from rating ")
    public List<Rating> queryAllRating();
    //根据关键词查询评价
    public List<Rating> queryLikeRating(@Param("keyword") String keyword);
    //根据用户id查询评价
    @Select("select * from rating where user_id = #{userId}")
    public List<Rating> queryRatingByUserId(int userId);
}
